<?php
/**
 * Created by PhpStorm.
 * User: mrjnamei
 * Date: 17-5-12
 * Time: 上午10:39
 */

namespace App\Winged\Patients\Api;

class Patients extends Api
{

    /**
     * 接口
     * @var array
     */
    public static $actions = [
        // 获取所有患者 GET   index 页码　　number 页数
        'getAllPatient'            => 'doctor/patient?index=0&number=2000',
        //获取患者列表 GET   index 页码　　number 页数
        'getPatient'               => 'doctor/patient?index=%s&number=%s',
        // 获取所有患者数目 GET
        'getPatientCount'          => 'doctor/patient/count',
        //获得各种类型患者的数目 GET
        'getPatientStatistic'      => 'doctor/patient/statistic',
        //获取各种类型患者列表　　unknowen condition
        'getPatientCondition'      => 'doctor/patient/condition?condition=%s&index=%s&number=%s',
        // 不知道是啥 unknowen condition
        'getPatientConditionCount' => 'doctor/patient/condition/count?condition=%s',
        // 获取患者详情 patientId
        'getPatientDetail'         => 'doctor/patient/%s',
        // 更新患者信息 PUT
        'updatePatientInfo'        => 'doctor/patient',
        'existed'                   => 'doctor/patient/existed/%s',
    ];


    /**
     * 获取患者列表
     * @param $currentPage 页码
     * @return Collection|static
     */
    public static function makePatients($currentPage, $currentPageSize)
    {
        $patients = self::doGet('getPatient', $currentPage, $currentPageSize);
        $patients = empty($patients) ? [] : $patients->map(function ($item, $index) {
            if (!array_key_exists('lastSurgeryDate', $item['properties'])) {
                $item['properties']['lastSurgeryDate'] = "";
            }
            if (!array_key_exists('lastHospitalizeDate', $item['properties'])) {
                $item['properties']['lastHospitalizeDate'] = "";
            }
            if (!array_key_exists('caseCount', $item['properties'])) {
                $item['properties']['caseCount'] = 0;
            }
            return $item;
        });
        return $patients;
    }

    /**
     * @param $condition　　条件
     * @param $currentPage 页码
     * @return Collection|static
     */
    public static function makePatientsByCondition($condition, $currentPage, $currentPageSize)
    {
        $patients = self::doGet('getPatientCondition', $condition, $currentPage, $currentPageSize);
        $patients = empty($patients) ? [] : $patients->map(function ($item, $index) {
            if (!array_key_exists('lastSurgeryDate', $item['properties'])) {
                $item['properties']['lastSurgeryDate'] = "";
            }
            if (!array_key_exists('lastHospitalizeDate', $item['properties'])) {
                $item['properties']['lastHospitalizeDate'] = '';
            }
            if (!array_key_exists('caseCount', $item['properties'])) {
                $item['properties']['caseCount'] = 0;
            }
            return $item;
        });
        return $patients;
    }

    /**
     * 获取count
     */
    public static function getPatientCount()
    {
        return self::doGet('getPatientCount');
    }

    /**
     * 获取filter
     */
    public static function getPatientStatistic()
    {
        return self::doGet('getPatientStatistic');
    }

    /**
     * 获取患者详情
     * @param $patient_id
     * @return \Illuminate\Support\Collection|string
     */
    public static function getPatientDetail($patient_id)
    {
        return self::doGet('getPatientDetail', $patient_id);
    }

    /**
     * 更新患者信息
     */
    public static function updatePatientInfo($info = [])
    {
        return self::doPut('updatePatientInfo' , $info);
    }
    
    /**
     * 判断用户存不存在
     */
    public static function existed($id)
    {
        return self::doGet('existed' ,$id);
    }
}
